package org.openzip.jarsfx.unpacking.view.swing.util;

import javax.swing.*;
import javax.swing.border.Border;

import java.awt.BorderLayout;
import java.awt.Component;

/**
 * This is a utility class. It creates a <code>JPanel</code> with
 * <code>BorderLayout</code>. Available to the user are top, middle and bottom
 * component. Between those containers is a separator <code>JSeparator</code>.
 * 
 * @author Jakub Závěrka
 */
public class StandardForm
{
	private JPanel panel;

	/**
	 * Constructor for the top, middle and buttom component.
	 * 
	 * @param top
	 *           Top component
	 * @param middle
	 *           Middle component
	 * @param bottom
	 *           Bottom component
	 */
	public StandardForm(Component top, Component middle, Component bottom){
		panel = new JPanel(new BorderLayout());

		Box topContainer;
		Box bottomContainer = new Box(BoxLayout.Y_AXIS);

		if(top != null){
			topContainer = new Box(BoxLayout.Y_AXIS);
			topContainer.add(top);
			topContainer.add(new JSeparator());

			panel.add(topContainer, BorderLayout.NORTH);
		}
		
		if(middle != null){
			panel.add(middle, BorderLayout.CENTER);
		}
		
		if(bottom != null){
			bottomContainer.add(new JSeparator());
			bottomContainer.add(bottom);
			panel.add(bottomContainer, BorderLayout.SOUTH);
		}
	}
	
	/**
	 * This will set the specified border to the whole container. The most used
	 * way of this is to pass an empty border to make an optical gap around this
	 * container.
	 * 
	 * @param border
	 *           Specified border to add around the whole container.
	 */
	public void setBorder(Border border){
		panel.setBorder(border);
	}

	/**
	 * This will return the <code>Container</code> with added components.
	 */
	public JComponent getJComponent(){
		return panel;
	}
}
